#coding:utf-8
from . import db 
from werkzeug.security import  generate_password_hash,check_password_hash
from sqlalchemy.orm import relationship,backref

from sqlalchemy.orm import relationship,backref


class Users(db.Model):
    __tablename__='Users'
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(255))
    hash_psw=db.Column(db.String(255))

    @property
    def password(self):
        pass

    @password.setter
    def password(self,psw):
        self.hash_psw=generate_password_hash(psw)

    def verify_psw(self,psw):
        return check_password_hash(self.hash_psw,psw)
    

# class Tv(db.Model):
#     __tablename__='tv'
#     id=db.Column(db.Integer,primary_key=True)
#     name=db.Column(db.String(255))
#     # 介绍
#     introd=db.Column(db.String(255))
#     teacher=db.Column(db.String(255))
#     # 视频播放次数
#     play=db.Column(db.Integer)
#     time=db.Column(db.Integer)


# class 

class Kinds(db.Model):
    __tablename__='kinds'
    id = db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(255))
    couses=relationship('Courses',backref='kinds',cascade='delete')

class Courses(db.Model):
    __tablename__='t_courses'
    id= db.Column(db.Integer,primary_key=True)
    title=db.Column(db.String(255))
    abstract=db.Column(db.String(255))
    addtime=db.Column(db.DateTime)
    k_id=db.Column(db.Integer,db.ForeignKey('kinds.id'))
    videos=relationship('Videos',backref='courses',cascade='delete')



class Videos(db.Model):
    __tablename__='t_videos'
    id= db.Column(db.Integer,primary_key=True)
    title=db.Column(db.String(255))
    time =db.Column(db.Integer)
    hist=db.Column(db.Integer)
    addtime=db.Column(db.DateTime)
    abstract=db.Column(db.String(255))
    t_id=db.Column(db.Integer)
    c_id=db.Column(db.Integer,db.ForeignKey('t_courses.id'))



class Teacher(db.Model):
    __tablename__='teacher'
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(255))
    # 教师简介
    abstract=db.Column(db.String(255))
    # 职称
    level=db.Column(db.String(255))
    



